package com.nnnu.wsnackshop.handler;

import com.alibaba.excel.write.handler.SheetWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder;
import org.apache.poi.ss.usermodel.Sheet;
import org.jetbrains.annotations.NotNull;

public class CustomSheetWriteHandler implements SheetWriteHandler {

    @Override
    public void beforeSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {
    }

    @Override
    public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, @NotNull WriteSheetHolder writeSheetHolder) {
        Sheet sheet = writeSheetHolder.getSheet();

        // 设置列宽（按列索引），单位为 1/256 字符宽度
        // F 列为图片列，索引为 5，从 0 开始
        sheet.setColumnWidth(0, 15 * 256); // 门店名
        sheet.setColumnWidth(1, 15 * 256); // 分类名
        sheet.setColumnWidth(2, 15 * 256); // 品牌名
        sheet.setColumnWidth(3, 15 * 256); // 商品名
        sheet.setColumnWidth(4, 20 * 256); // 描述
        sheet.setColumnWidth(5, 25 * 256); // 图片列
        sheet.setColumnWidth(6, 8 * 256); // 状态列
    }
}

